<?
$rx = Q1("select * from language limit 1");
if(!isset($opr))
{
	
	$rs = Q2("select * from link order by link_id");
	$txt="";
	$i=0;
	foreach($rs as $r)
	{	if($i%2==0)
		{
			$bb  = "#d2d2d2";
		}
		else
		{
			$bb= "#E6E6E6";
		}
		$txt.="<tr height=45 bgcolor='$bb' style='color:black'>";
		$txt.="<td align='center'>$r[link_name1]</td>";
		$txt.="<td align='center'>$r[link_name2]</td>";
		$txt.="<td align='center'>$r[url]</td>";
		$txt.="<td align='center'><a href='?body=link&opr=upd&link_id=$r[link_id]'>upd</a></td>";
		$txt.="<td align='center'><a href='?body=link&opr=del&link_id=$r[link_id]' onclick='if(!confirm(\"Are you sure to delete?\")) return false;'>del</a></td>";
		$txt.="</tr>";
		$i++;
	}

	?>
<h2>Link Management</h2>
	<center><input type='button' value='Add' onclick='location="?body=link&opr=add"'></center><br/>
<table align=center width='95%' style='border-collapse:collapse;font-weight:bold' border=1>

	<tr bgcolor=#5F5F5F height=45 style='color:white;'>
		<td align=center><?=$rx[lang1]?></td>
		<td align=center><?=$rx[lang2]?></td>
		<td align=center>url</td>
		<td align=center>update</td>
		<td align=center>delete</td>
	</tr>
	<?
	if($txt=="")
	{
		?>
	<tr height='45'>
		<td align=center colspan=5>No data</td>
	</tr>
		<?
	}
	else
	{
		echo $txt;
	}

	?>
</table>



	<?

}
else if($opr=="add")
{
	if(!isset($send))
	{
	?>
<h2>Add Link</h2>
<form action='?body=link&opr=add&send=1' method='post'>
	<table align=center>
		<tr>
			<td>title <?=$rx[lang1]?></td>
			<td><input type="text" name='name1'></td>
		</tr>
		<tr>
			<td>title <?=$rx[lang2]?></td>
			<td><input type="text" name='name2'></td>
		</tr>
		<tr>
			<td>url</td>
			<td><input type="text" name='url'></td>
		</tr>
		<tr>
			<td colspan=2><input type='submit' value='Add'></td>
		</tr>
	</table>

</form>

	<?
	}
	else
	{
		$arr['link_name1'] = $_POST["name1"];
		$arr['link_name2'] = $_POST["name2"];
		$arr['url'] = $_POST["url"];
		Qinsert("link","",$arr);

		?>
<script>location='index.php?body=link'</script>
		<?

			exit;
	
	}
}
else if($opr=="upd")
{
	if(!isset($send))
	{
		$rs = Q1("select * from link where link_id = '$link_id'");
		?>
<h2>Update Link</h2>
<form action='?body=link&opr=upd&send=1&link_id=<?=$link_id?>' method='post'>
	<table align=center>
		<tr>
			<td>title <?=$rx[lang1]?></td>
			<td><input type="text" name='name1' value='<?=$rs[link_name1]?>'></td>
		</tr>
		<tr>
			<td>title <?=$rx[lang2]?></td>
			<td><input type="text" name='name2' value='<?=$rs[link_name2]?>'></td>
		</tr>
		<tr>
			<td>url</td>
			<td><input type="text" name='url' value='<?=$rs[url]?>'></td>
		</tr>
		<tr>
			<td colspan=2><input type='submit' value='Update'></td>
		</tr>
	</table>

</form>

	<?

	}
	else
	{
		$arr['link_name1'] = $_POST["name1"];
		$arr['link_name2'] = $_POST["name2"];
		$arr['url'] = $_POST["url"];
		Qupdate("link","",$arr,"link_id='$link_id'");

		?>
<script>location='index.php?body=link'</script>
		<?

			exit;
	}

}
else if($opr=="del")
{

	mysql_query("DELETE FROM link WHERE link_id = '$link_id'");
	?>
<script>location='index.php?body=link'</script>
		<?

			exit;
}

?>